---
description: "Reference for Nitric's v0 JVM library - Store a new secret value"
---

# JVM - secret.put()

Store a new secret value, creating a new [version](./secret-version) to store the value.

<Tabs syncKey="jvm-lang">

<TabItem label="Java">

```java
import io.nitric.Nitric;
import io.nitric.resources.SecretPermission;

public class Application {
  public static void main(String[] args) {
    var secrets = Nitric.INSTANCE.secret("apiKey").with(SecretPermission.Put);

    secrets.put("6c3199a3-094e-4797-bfc9-9ee2a7839286")

    Nitric.INSTANCE.run();
  }
}
```

</TabItem>

<TabItem label="Kotlin">

```kotlin
import io.nitric.Nitric
import io.nitric.resources.SecretPermission

fun main() {
  val secrets = Nitric.secret("apiKey").with(SecretPermission.Put)

  secrets.put("6c3199a3-094e-4797-bfc9-9ee2a7839286")

  Nitric.run()
}
```

</TabItem>

</Tabs>

## Parameters

<Properties>
  <Property name="secret" required type="String or []byte">
    The new secret value to store in the secrets manager.
  </Property>
</Properties>

### Notes

A new secret version is always created when calling `put()`, the versions will automatically be provided a unique id. This behavior is dependent on the underlying secrets manager.

## Examples

### Store a new secret value

<Tabs syncKey="jvm-lang">

<TabItem label="Java">

```java
import io.nitric.Nitric;
import io.nitric.resources.SecretPermission;

public class Application {
  public static void main(String[] args) {
    var secrets = Nitric.INSTANCE.secret("apiKey").with(SecretPermission.Put);

    secrets.put("6c3199a3-094e-4797-bfc9-9ee2a7839286")

    Nitric.INSTANCE.run();
  }
}
```

</TabItem>

<TabItem label="Kotlin">

```kotlin
import io.nitric.Nitric
import io.nitric.resources.SecretPermission

fun main() {
  val secrets = Nitric.secret("apiKey").with(SecretPermission.Put)

  secrets.put("6c3199a3-094e-4797-bfc9-9ee2a7839286")

  Nitric.run()
}
```

</TabItem>

</Tabs>
### Get the id of a new secret version

Calling `put()` returns a promise to a reference to the new secret version. Storing the ID of the new version can be useful if you need to retrieve that specific value again in future using [version.access()](./secret-version-access)

<Tabs syncKey="jvm-lang">

<TabItem label="Java">

```java
import io.nitric.Nitric;
import io.nitric.resources.SecretPermission;

public class Application {
  public static void main(String[] args) {
    var secrets = Nitric.INSTANCE.secret("apiKey").with(SecretPermission.Put);

    var newApiKeyVersionRef = secrets.put("6c3199a3-094e-4797-bfc9-9ee2a7839286");

    var version = newApiKeyVersionRef.getVersion();

    Nitric.INSTANCE.run();
  }
}
```

</TabItem>

<TabItem label="Kotlin">

```kotlin
import io.nitric.Nitric;
import io.nitric.resources.SecretPermission

fun main() {
  val secrets = Nitric.secret("apiKey").with(SecretPermission.Put)

  val newApiKeyVersionRef = secrets.put("6c3199a3-094e-4797-bfc9-9ee2a7839286")

  val version = newApiKeyVersionRef.version

  Nitric.run()
}
```

</TabItem>

</Tabs>
